#ifndef  _FLAPP_DISPLAY_H_
#define  _FLAPP_DISPLAY_H_
#include <stdint.h>


#define DIS_SEND_HEAH_1				0x5A
#define DIS_SEND_HEAH_2				0xA5

#define DIS_CMD_CUT_MODE			0x01			//页面切换模式
#define DIS_CMD_CUT_ST				0x5A			//启动页面处理
#define DIS_CMD_WR						0x82			//写指令
#define DIS_CMD_RD						0x83			//读指令


#define DIS_ADDR_CUT_PAGE			0x0084		//切页地址
#define DIS_ADDR_AUTO 				0x1004		//模式显示地址
#define DIS_ADDR_ION					0x1006		//离子显示地址
#define DIS_ADDR_FIL					0x1008		//滤网显示地址
#define DIS_ADDR_NET					0x100A		//4G显示地址
#define DIS_ADDR_FAN					0x100C		//风速显示地址
#define DIS_ADDR_PM25					0x1010		//PM2.5显示地址
#define DIS_ADDR_VOC					0x1016		//VOC显示地址
#define DIS_ADDR_TEMP					0x101E		//温度显示地址
#define DIS_ADDR_HUM					0x1024		//湿度显示地址

#define DIS_LEN_DEFAULT				5					//1位写入长度
#define DIS_CUT_PAGE					7					//切页
#define DIS_LEN_FAN						9					//2位写入长度
#define DIS_LEN_TEST					11				
#define DIS_LEN_NUM						13				//3位写入长度
#define DIS_LEN_VOC						17
#define DIS_LEN_TMP_GROUP			25
#define DIS_LEN_AIR_GROUP			29


/*test icon*/
#define TEST_ICON_VERSION			0x4000		
#define TEST_ICON_FAN_LOW 		0x4004		
#define TEST_ICON_FAN_MID			0x4008		
#define TEST_ICON_FAN_HIGH		0x400C		
#define TEST_ICON_VOC					0x4010		
#define TEST_ICON_ION					0x4014		
#define TEST_ICON_TEMP				0x4018		
#define TEST_ICON_HUN					0x401C		
#define TEST_ICON_PM25				0x4020		
#define TEST_ICON_LCD					0x4024		
#define TEST_ICON_CSQ					0x4028		
#define TEST_ICON_ID					0x402C		
#define TEST_ICON_ALL_PASSED	0x4040		

#define TEST_TEXT_VERSION			0x4002		
#define TEST_TEXT_FAN_LOW 		0x4006		
#define TEST_TEXT_FAN_MID			0x400A	
#define TEST_TEXT_FAN_HIGH		0x400E	
#define TEST_TEXT_VOC					0x4012		
#define TEST_TEXT_ION					0x4016		
#define TEST_TEXT_TEMP				0x401A		
#define TEST_TEXT_HUN					0x401E		
#define TEST_TEXT_PM25				0x4022		
#define TEST_TEXT_LCD					0x4026		
#define TEST_TEXT_CSQ					0x402A		
#define TEST_TEXT_ID					0x402E		

typedef enum
{
	DIS_HEAD_1 				= 0,		//发送显示包头
	DIS_HEAD_2				= 1,
	DIS_DATA_LEN			= 2,
	DIS_CMD						= 3,
	DIS_ADDR_H				= 4,
	DIS_ADDR_L				= 5,
	DIS_DATA1_H,
	DIS_DATA1_L				= 7,
	DIS_RES1_H,
	DIS_RES1_L,
	DIS_DATA2_H,
	DIS_DATA2_L				= 11,
	DIS_RES2_H,
	DIS_RES2_L,
	DIS_DATA3_H,
	DIS_DATA3_L				= 15,
	DIS_RES3_H,
	DIS_RES3_L,
	DIS_DATA4_H,
	DIS_DATA4_L				= 19,
	DIS_RES4_H,
	DIS_RES4_L,
	DIS_DATA5_H,
	DIS_DATA5_L				= 23,
	DIS_RES5_H,
	DIS_RES5_L,
	DIS_DATA6_H,
	DIS_DATA6_L				= 27,
	DIS_RES6_H,
	DIS_RES6_L,
	DIS_DATA7_H,
	DIS_DATA7_L				= 31,
}flapp_dis_air_quality_e;

typedef enum
{
	AIR_GOOD 					= 0,		
	AIR_GENERAL,
	AIR_BAD,
	AIR_NOT						= 0xff,
	AIR_LEVEL_MAX,
}flapp_air_level_e;

typedef enum
{
	PAGE_POWER_ON 					= 0,		
	PAGE_AIR_GOOD,
	PAGE_AIR_GENERA,
	PAGE_AIR_BAD,
	PAGE_TEST_MODE,
	PAGE_JIANBIAN,
	PAGE_RED,
	PAGE_BLUE,
	PAGE_GREEN,
	PAGE_WHITE,
	PAGE_BLACK,
	PAGE_TEST_FINISH,
	PAGE_NUM_MAX,
}flapp_page_num_e;

typedef enum
{
	DIS_OFF 					= 0,		
	DIS_PASS,
	DIS_FAIL,
	DIS_MAX						= 0xff,
}flapp_test_dis_sta_e;


typedef enum
{
	ASC_0 					= 0x30,		
	ASC_1,
	ASC_2,
	ASC_3,
	ASC_4,
	ASC_5,
	ASC_6,
	ASC_7,
	ASC_8,
	ASC_9,
	ASC_G						= 0x47,
	ASC_K						= 0x4b,
	ASC_N						= 0x4e,
	ASC_O						= 0x4f,
	ASC_V						= 0x56,
	ASC_NOT					= 0xff,
	ASC_MAX,
}flapp_ascill_e;

//定义一个显示内容结构体 
typedef struct flapp_dis
{
	uint8_t flag_test;						//测试模式标志
	uint8_t flag_auto;						//自动标志	
	uint8_t flag_ion;							//离子标志
	uint8_t flag_filter;					//滤网标志
	uint8_t flag_net;							//4G标志
	uint8_t flag_temp;						//温度标志,-号		
	uint8_t master_err;						//主机错误	
	uint8_t slave_err;						//从机错误		
	uint8_t slave_addr;						//从机地址			
	uint16_t value_air[2];				//PM2.5、VOC值
	int16_t val_t_h_buf[2];				//温湿度值
	uint8_t value_fan;						//风速值
	uint16_t voc_count_down;			//VOC倒计时
	uint16_t slave_err_report;		//从机故障上报：从机（固定2）+从机设备号+离子故障（有就1）+风扇故障（有就2）
	flapp_air_level_e air_level;	//空气质量等级	
}flapp_dis_t;

struct flapp_dis flapp_get_device_status(void);
void flapp_display_init(void);
void flapp_dis_run(void);
uint8_t flapp_get_master_err_bit(uint8_t bit);
uint8_t flapp_get_slave_err_bit(uint8_t bit);
void flapp_set_master_err(uint8_t flag,uint8_t value);
uint8_t flapp_get_slave_err(void);
void flapp_set_slave_err(uint8_t flag,uint8_t value);
void flapp_set_slave_addr(uint8_t addr);
void flapp_set_slave_err_report(uint16_t err_report);
#endif

